package com.bjpower.utlis;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;


import java.util.Date;
import java.util.HashMap;

public class JwtUtils{

    //自定义密钥
    private static final String SECRET_KEY = "hn$unv<45T^B+$#-o12FDV-uh";

    public static String createJwt(String Data , int timeoutMinutes){

        HashMap<String, Object> map = new HashMap<>();
        map.put("alg", "HS256");
        map.put("typ", "JWT");
        //设置过期时间
        DateTime expire = DateUtil.offsetMillisecond(new Date(),timeoutMinutes);
        return JWT.create()
                .withHeader(map)
                .withClaim("data", Data)
                .withExpiresAt(expire)
                .sign(Algorithm.HMAC256(SECRET_KEY));
    }

}
